﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="aadressType", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(AadressType))]
    public class AadressTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IAadressType clazz;
        
        public AadressTypeSerializer(IAadressType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Asukoht!=null) {
                Writer.WriteStartElement("asukoht");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Asukoht))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Ehak!=null) {
                Writer.WriteStartElement("ehak");
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", "x_ehak");
                Writer.WriteString(clazz.Ehak.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Riik!=null) {
                Writer.WriteStartElement("riik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Riik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Postiindeks!=null) {
                Writer.WriteStartElement("postiindeks");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Postiindeks))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="asukoht") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadressType>asukoht");
                }
                clazz.Asukoht = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("asukoht")).Value;
            }
            if (Reader.LocalName=="ehak") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadressType>ehak");
                }
                clazz.Ehak = new global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.XEhak(Reader.ReadElementString("ehak"));
            }
            if (Reader.LocalName=="riik") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Riik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("riik")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="postiindeks") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>aadressType>postiindeks");
                }
                clazz.Postiindeks = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("postiindeks")).Value;
            }
        }
    }
}
